package ar.edu.itba.pod.main;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.joda.time.Duration;

import ar.edu.itba.pod.agent.market.Consumer;
import ar.edu.itba.pod.agent.market.Factory;
import ar.edu.itba.pod.agent.market.Market;
import ar.edu.itba.pod.agent.market.Producer;
import ar.edu.itba.pod.agent.market.Resource;
import ar.edu.itba.pod.agent.runner.Simulation;
import ar.edu.itba.pod.multithread.LocalSimulation;
import ar.edu.itba.pod.time.TimeMappers;

import com.google.common.collect.ConcurrentHashMultiset;
import com.google.common.collect.Multiset;

public class SingleSimulationMain {
	private static Logger logger = Logger.getLogger(SingleSimulationMain.class);
	
	public static void main(String[] args) {
		
		PropertyConfigurator.configure("config/log4j.properties");
		
		
		Simulation simulation = new LocalSimulation(TimeMappers.oneSecondEach(Duration.standardSeconds(1)));
		
		Resource resourceA1 = new Resource("A", "a1");
		Resource resourceA2 = new Resource("A", "a1");
		Resource resourceB1 = new Resource("B", "b1");
		
		Multiset<Resource> resourceB1requierement = ConcurrentHashMultiset.create();
		resourceB1requierement.add(resourceA1);
		resourceB1requierement.add(resourceA2);

		Factory factoryB1 = new Factory("factory B1", resourceB1, resourceB1requierement , Duration.standardSeconds(2), 5);
		simulation.add(factoryB1);
		
		Market marketA1 = new Market("market for A1", resourceA1);
		simulation.add(marketA1);
		Market marketA2 = new Market("market for A2", resourceA2);
		simulation.add(marketA2);
		Market marketB3 = new Market("market for B1", resourceB1);
		simulation.add(marketB3);
		
		Producer producerA1 = new Producer("producer A1", resourceA1, Duration.standardSeconds(1), 1);
		simulation.add(producerA1);
		Producer producerA2 = new Producer("producer A1", resourceA2, Duration.standardSeconds(2), 1);
		simulation.add(producerA2);
		
		Consumer consumerA1 = new Consumer("consumer A1", resourceA1, Duration.standardSeconds(5), 1);
		simulation.add(consumerA1);
		
		Consumer consumerB1 = new Consumer("consumer B1", resourceB1, Duration.standardSeconds(2), 1);
		simulation.add(consumerB1);
		
		logger.info("Agents added to simulation");
		
		simulation.start(Duration.standardSeconds(10));
		
	}

}
